package com.qys.livesMall.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.framework.view.BaseQuery;
import com.qys.livesMall.kafka.entity.log.SystemLog;
import com.qys.livesMall.kafka.service.SystemLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.YearMonth;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: dp
 * Date: 2023/06/07
 * Time: 11:27
 * DESCRIPTION:
 */
@RestController
@RequestMapping("/sys/log")
@Tag(name = "后台管理-系统操作日志")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SystemLogController {

    private final SystemLogService systemLogService;

    @PostMapping("/page")
    @Operation(summary = "分页查询系统操作日志信息")
    public R<Page<SystemLog>> page(@RequestBody BaseQuery baseQuery) {
        org.springframework.data.domain.Page<SystemLog> page = systemLogService.page(
                PageRequest.of(baseQuery.getPageNum() - 1, baseQuery.getPageSize()),
                baseQuery.getStartTime(), baseQuery.getEndTime());

        Page<SystemLog> resultPage = new Page<>(baseQuery.getPageNum(), baseQuery.getPageSize());
        resultPage.setRecords(page.getContent());
        resultPage.setTotal(page.getTotalElements());
        return R.ok(resultPage);
    }
}
